/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package handler;

import Socket.Sender;
import Socket.SocketSingleton;
import map_decripter.MapDecripter;
import model.Robot;

/**
 *
 * @author minhtue001
 */
public class Receiver {
    public static int numS = 0;
    public void receive(String data) {
        if (data == null || data.length() < 1)
            return;
        System.out.println("RECEIVE: " + data);
        switch (data.charAt(0)) {
            case 's':
                Sender.sendToArduino("S");
                System.out.println("DM");
                numS++;
                if (numS == 2) {
                    System.out.println("??");
                    (new MapDecripter()).gen();
                    System.out.println("??");
                    (new AlgorithmHandler()).handle(data);
                }
                break;
            case 'X':
                Robot.getInstance().setX(17);
                Robot.getInstance().setY(12);
                Robot.getInstance().setDirection(Robot.LEFT);
                break;
            case 'Y':
                Robot.getInstance().setX(0);
                Robot.getInstance().setY(0);
                Robot.getInstance().setDirection(Robot.RIGHT);
                break;
            case 'A':
                (new AlgorithmHandler()).handle(data);
                break;
            case 'L':
                (new RotateHandler()).handle(data);
                break;
            case 'R':
                (new RotateHandler()).handle(data);
                break;
            case 'G':
                (new MoveHandler()).handle(data);
                break;
            case 'S':
                (new SensorHandler()).handle(data);
                break;
            
        }
    }
}
